package br.com.fogas.notafiscal.preco.zfp0;

import java.math.BigDecimal;
import java.util.Date;

import br.com.fogas.database.FogasDatabase;
import br.com.fogas.database.exception.PrecoUnitarioException;

public class A903_ZFP0 extends PrecoResponsability {

	private String condicao;

	private String material;

	private Date dataPedido;
	
	private FogasDatabase database;

	public A903_ZFP0(FogasDatabase database, String condicao, String material, Date dataPedido) {
		this.database = database;
		this.condicao = condicao;
		this.material = material;
		this.dataPedido = dataPedido;
	}

	@Override
	public BigDecimal atende() throws PrecoUnitarioException {
		try {
			BigDecimal preco = database.getA903().getPreco(condicao, material, dataPedido);
			if(preco == null && proximo != null) {
				return proximo.atende();
			}
			return preco;
		} catch (Exception e) {
			throw new PrecoUnitarioException(e.getMessage());
		}
	}
}